package com.mf.ergate.web.service.opt.impl;

import com.mf.ergate.api.opt.OrgContractRemoteService;
import com.mf.ergate.api.opt.model.dto.*;
import com.mf.ergate.api.opt.model.vo.OrgContractVo;
import com.mf.ergate.api.opt.model.vo.OrgInfoVo;
import com.mf.ergate.web.service.opt.OrgContractService;
import com.mf.ergate.web.service.opt.OrgInfoService;
import com.mf.framework.common.model.Page;
import com.mf.framework.common.model.RemotePage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 机构合同Service层实现类
* User: zhaoming
* DateTime: 2019-04-16
* To change this template use File | Settings | File Templates.
**/
@Service
public class OrgContractServiceImpl implements OrgContractService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private OrgContractRemoteService orgContractRemoteService;
    @Autowired
    private OrgInfoService orgInfoService;

    /**
     * 新增
     * @param orgContractCreateDto 机构合同新增Dto
     * @return 机构合同
     */
    public OrgContractVo insert(OrgContractCreateDto orgContractCreateDto){
        return orgContractRemoteService.insert(orgContractCreateDto).getContent();
    }

    /**
     * 根据唯一编号更新
     * @param orgContractUpdateDto 机构合同更新Dto
     * @return 执行结果
     */
    public Boolean updateByUniqueNo(OrgContractUpdateDto orgContractUpdateDto){
        return orgContractRemoteService.updateByUniqueNo(orgContractUpdateDto).getContent();
    }

    /**
     * 根据唯一编号删除(逻辑删除)
     * @param orgContractDeleteDto 机构合同删除Dto
     * @return 执行结果
     */
    public Boolean deleteByUniqueNo(OrgContractDeleteDto orgContractDeleteDto){
        return orgContractRemoteService.deleteByUniqueNo(orgContractDeleteDto).getContent();
    }

    /**
     * 根据唯一编号查询
     * @param uniqueNo 机构合同编号
     * @return 机构合同
     */
    public OrgContractVo selectByUniqueNo(String uniqueNo){
        return orgContractRemoteService.selectByUniqueNo(uniqueNo).getContent();
    }

    /**
     * 根据条件查询
     * @param orgContractQueryDto 机构合同查询Dto
     * @return 机构合同列表
     */
    public List<OrgContractVo> selectByCondition(OrgContractQueryDto orgContractQueryDto){
        return orgContractRemoteService.selectByCondition(orgContractQueryDto).getContent();
    }

    /**
     * 根据条件查询数量
     * @param orgContractQueryDto 机构合同查询Dto
     * @return 数量
     */
    public Integer selectCount(OrgContractQueryDto orgContractQueryDto){
        return orgContractRemoteService.selectCount(orgContractQueryDto).getContent();
    }

    /**
     * 根据条件分页查询
     * @param page 远程分页
     * @param orgContractQueryDto 机构合同查询Dto
     * @return 机构合同分页列表
     */
    public Page<OrgContractVo> selectPage(Page page, OrgContractQueryDto orgContractQueryDto){
        Page<OrgContractVo> orgContractVoPage = orgContractRemoteService.selectPage(new RemotePage<>(orgContractQueryDto, page)).getContent();
        for(OrgContractVo orgContractVo: orgContractVoPage.getContent()){
            orgContractVo.setOrgName(orgInfoService.selectByUniqueNo(orgContractVo.getOrgNo()).getOrgName());
        }
        return orgContractVoPage;
    }

    /**
     * 获取机构列表
     * @return 机构列表
     */
    public List<OrgInfoVo> getOrgInfos(){
        return orgInfoService.selectByCondition(new OrgInfoQueryDto());
    }

}
